package finalproject.model.player;

import java.util.Stack;

import finalproject.model.rooms.Room;

/**
 * the path the player took
 * @author Nicolas Bighetti and Yassine Tijani
 */
public class Path {

	/**
	 * A stack containing the previous rooms
	 */
	private Stack<Room> previousRooms;

	/**
	 * Default constructor
	 */
	public Path()
	{
		this.previousRooms = new Stack<Room>();
	}

	/**
	 * @return the previous rooms
	 */
	public Stack<Room> getPreviousRooms() {
		return previousRooms;
	}

	/**
	 * 
	 * @param previousRooms the previous room
	 */
	public void setPreviousRooms(Stack<Room> previousRooms) {
		this.previousRooms = previousRooms;
	}

	/**
	 * Add a room on top of the stack
	 * @param oldRoom the room to push
	 * @return if the room was successfully pushed
	 */
	public boolean addRoom(Room oldRoom)
	{
		try
		{
			previousRooms.push(oldRoom);
			return true;
		}
		catch(StackOverflowError e)
		{
			this.previousRooms = new Stack<Room>();
			return false;
		}
	}

	/**
	 * Allow the player to go back
	 * @return the poped room
	 */
	public Room goBack()
	{
		if(previousRooms.isEmpty())
		{
			return null;
		}
		else
		{
			return previousRooms.pop();
		}
	}
}
